<template>
	<view class="profile">
		<cu-custom bgColor="bg-gradual-orange" :isBack="true">
			<block slot="content">云音箱</block>
		</cu-custom>
		<view class="cu-form-group">
			<view class="title">设备号</view>
			<input v-model="form.speaker"></input>
		</view>
		<view class="padding flex flex-direction">
			<button class="cu-btn bg-gradual-orange margin-tb-sm lg" @tap="submit">提交</button>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	import shop from '@/api/shop';
	export default {
		data() {
			return {
				form: {
					speaker: ''
				},
				info: {}
			}
		},
		computed: {
			...mapState(['userInfo']),
		},
		onLoad(options) {
			if (options.spid) {
				this.spid = options.spid
			}
			this.loadInfo();
		},
		methods: {
			async loadInfo() {
				shop.speaker({
					spid: this.spid
				}).then(res => {
					if (res.code === 1) {
						this.info = res.data;
						if (this.info) {
							this.form.speaker = this.info.speaker;

						}
					} else {
						this.toast(res.msg);
					}
				})
			},
			submit() {
				if (this.loading) {
					return;
				}
				this.loading = true;
				setTimeout(() => {
					this.loading = false
				}, 7000)

				console.log(this.form)
				this.form.spid = this.spid;
				shop.speakerUpdate(this.form).then(res => {
					this.loading = false;
					this.toast(res.msg);
				})
			},
		}
	}
</script>

<style>

</style>